<?php
/**
*
* @package ucp
* @copyright (c) 2009 kmklr72
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* ucp_social_network
* @package ucp
*/
class ucp_social_network
{
	var $u_action;

	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
		global $sn;

		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

		$submit	= (isset($_POST['submit'])) ? true : false;
		$s_hidden_fields = '';

		$user->add_lang('mods/social_network_mod');

		switch ($mode)
		{
			case 'emb':
				if ($submit)
				{
					$block_info = utf8_normalize_nfc(request_var('profile_info_block', ''));
					$uid = $bitfield = $options = '';
					$allow_bbcode = $allow_urls = $allow_smilies = true;
					generate_text_for_storage($block_info, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);

					$sql_ary = array(
						'profile_info_block'	=> $block_info,
						'bbcode_uid'			=> $uid,
						'bbcode_bitfield'		=> $bitfield,
						'bbcode_options'		=> $options,
					);

					/*$sql = 'UPDATE ' . SN_PROFILE_DATA_TABLE . "
						SET profile_info_block = '" . $block_info . "'
						WHERE user_id = " . $user->data['user_id'];*/
					$sql = 'UPDATE ' . SN_PROFILE_DATA_TABLE . '
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
						WHERE user_id = ' . (int) $user->data['user_id'];
					$db->sql_query($sql);
				}
				else
				{
					$sql = 'SELECT profile_info_block, bbcode_uid
						FROM ' . SN_PROFILE_DATA_TABLE;
					$result = $db->sql_query($sql);
					$misc = $db->sql_fetchrow($result);
					$db->sql_freeresult($result);

					decode_message($misc['profile_info_block'], $misc['bbcode_uid']);

					$template->assign_vars(array(
						'S_EDIT_MISC_BLOCK'		=> true,
					));
				}
			break;

			default:
				trigger_error('NO_MODE', E_USER_ERROR);
			break;
		}

		$template->assign_vars(array(
			'L_TITLE'			=> $user->lang['FRAM_REQUESTS'],
		));

		$this->tpl_name = 'ucp_social_network';
		$this->page_title = 'FRAM_REQUESTS';
	}
}

?>